//
//  WithdrawalsViewController.m
//  tuanGG
//
//  Created by 微他 on 15/10/21.
//  Copyright (c) 2015年 weita. All rights reserved.
//

#import "WithdrawalsViewController.h"
#import "WithdrawalRecordTableViewCell.h"
@interface WithdrawalsViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong)NSMutableArray *dataArray;
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,assign)NSInteger index;
@end

@implementation WithdrawalsViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initlizeDataSource];
    [self NetWorking];
    [self addnavigationTitle:@"提现记录" navColor:@"4fd2be"];
    [self addTableView];
}
- (void)initlizeDataSource {
    _dataArray = [NSMutableArray array];
    _index = 1;
}
-(void)addTableView{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStyleGrouped];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [_tableView addHeaderWithTarget:self action:@selector(headerRereshing)];
    [_tableView addFooterWithTarget:self action:@selector(footerRereshing)];
    [_tableView registerClass:[WithdrawalRecordTableViewCell class] forCellReuseIdentifier:@"CELL"];
    [self.view addSubview:_tableView];
    UITextField *tiltie = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
    tiltie.backgroundColor = [UIColor whiteColor];
    tiltie.userInteractionEnabled = NO;
    tiltie.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 0)];
    tiltie.leftViewMode = UITextFieldViewModeAlways;
    tiltie.text = @"本月";
    _tableView.tableHeaderView = tiltie;
}
- (void)headerRereshing{
    _index = 1;
    [self NetWorking];
}
- (void)footerRereshing{
    _index++;
    [self NetWorking];

}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArray.count ;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    WithdrawalRecordTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CELL"];
    NSLog(@"数据：%@",_dataArray);
        [cell.headImage sd_setImageWithURL:nil placeholderImage:IMGNAME(@"图片1")];
        cell.nameLabel.text = @"我的账户";
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[_dataArray[indexPath.row][@"dateline"]integerValue]];
    NSLog(@"1296035591  = %@",confromTimesp);
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
    NSLog(@"confromTimespStr =  %@",confromTimespStr);
        cell.timeLabel.text = [NSString stringWithFormat:@"%@",confromTimespStr];
        cell.recordLabel.text = [NSString stringWithFormat:@"-%@",_dataArray[indexPath.row][@"num"]];
    return  cell;
}

- (void)NetWorking {
    NSDictionary *dictionary = @{@"page":[NSString stringWithFormat:@"%ld",(long)_index],@"size":@"10"};
    [GLAFRequest startRequest:cashrecode_url paramsDic:dictionary defaultdialog:NO ispost:NO handleSuccess:^(id sta, NSDictionary *paramsDic) {
//        NSLog(@"%@",sta);
        if ([sta[@"code"]integerValue] == 1) {
            [_tableView headerEndRefreshing];
            [_tableView footerEndRefreshing];
            _dataArray = [sta[@"recodeinfo"]mutableCopy];
            [_tableView reloadData];

        }else
        [_tableView headerEndRefreshing];
        [_tableView footerEndRefreshing];
    } doFinally:^(NSDictionary *paramsDic) {

    }];
}
@end
